//
//  GLTranslateAnimation.m
//  LMPhotoVideoSDK
//
//  Created by Aimar on 16/7/19.
//  Copyright © 2016年 魁钺会. All rights reserved.
//

#import "GLTranslateAnimation.h"

@interface GLTranslateAnimation ()

@property (nonatomic, assign)vec2       from;

@property (nonatomic, assign)vec2       to;

@end

@implementation GLTranslateAnimation

- (id)initWithFrom:(vec2)from to:(vec2)to {
    self = [super init];
    if (self) {
        self.from = from;
        self.to = to;
    }
    return self;
}

- (void)applyTransformation:(float)interpolatedTime outTransform:(Matrix4<float> *)transform {
    float dx = self.from.x;
    float dy = self.from.y;
    if (self.from.x != self.to.x) {
        dx = self.from.x + ((self.to.x - self.from.x) * interpolatedTime);
    }
    if (self.from.y != self.to.y) {
        dy = self.from.y + ((self.to.y - self.from.y) * interpolatedTime);
    }
    (*transform) = mat4::Translate(dx, -dy, 0) * (*transform);
}

@end
